﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Gencode.SQLWizz;
using System.IO;

namespace SQLWizz
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string dir = AppDomain.CurrentDomain.BaseDirectory + "SQL\\Log\\";

            try
            {
                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
            }
            catch (Exception)
            {
                try
                {
                    dir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Personalplaner\\SQL\\Log\\";
                    if (!Directory.Exists(dir))
                        Directory.CreateDirectory(dir);
                }
                catch (Exception) { }
            }

            string logName = dir + "SQLWiz-" + DateTime.Now.Date.ToShortDateString() + "_" + DateTime.Now.Hour.ToString() + "-" +
                DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + ".log";

            Gencode.Common.ActionLogger.Logger.LogName = logName;
            Gencode.Common.ActionLogger.Logger.UseLogger = true;
            
            try
            {
                Application.Run(new SQLWizzControler());
            }
            catch (Exception e)
            {
                MessageBox.Show("Es ist ein schwerer Fehler aufgetreten:\n" + e.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
    }
}